package com.learn.spring5.service;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.learn.spring5.dao.UserDao;

//在注解里面value的属性值可以不写
//默认值是类名称，首字母小写
//@Component(value = "userService") // <bean id="userService" class="...">
@Service
public class UserService
{
	@Value(value = "abc")
	private String name;
	// 定义dao类型属性
	// 不需要添加set方法
	// 添加注入属性注解
	// @Autowired // 根据类型注入实现类
	// @Qualifier(value = "userDaoImpl1") // 根据对象名称注入对应的实现类对象
	// private UserDao userDao;

	// @Resource // 根据类型进行注入
	@Resource(name = "userDaoImpl1") // 根据名称进行注入
	private UserDao userDao;

	public void add()
	{
		System.out.println("service add......" + name);
		userDao.add();
	}
}
